package com.bhs.sansonglogistics.ui.enterprise;

import static com.google.android.material.tabs.TabLayout.MODE_AUTO;
import static com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseActivity;
import com.bhs.sansonglogistics.base.BaseFragment;
import com.bhs.sansonglogistics.ui.home.FragmentAdapter;
import com.bhs.sansonglogistics.ui.home.SourceGoodsListFragment;
import com.bhs.sansonglogistics.view.SelectedFont3;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;

/**
 * 企业协作
 */
public class EnterpriseCollaborationActivity extends BaseActivity implements View.OnClickListener {

    private TabLayout mTabLayout;
    private ViewPager2 mViewPage;

    @Override
    public int initLayout() {
        return R.layout.activity_enterprise_collaboration;
    }

    @Override
    public void initView() {
        findViewById(R.id.tv_add_enterprise).setOnClickListener(this);
        mTabLayout = findViewById(R.id.tabLayout);
        mViewPage = findViewById(R.id.view_page);
    }

    @Override
    public void initData() {
        mTabLayout.setTabMode(MODE_SCROLLABLE);
        //tab切换时候的字体设置
        mTabLayout.addOnTabSelectedListener(new SelectedFont3(this));
        ArrayList<BaseFragment> fragments = new ArrayList<>();
        fragments.add(CollaborationFragment.newInstance(1));
        fragments.add(CollaborationFragment.newInstance(2));

        mViewPage.setOffscreenPageLimit(fragments.size());
        mViewPage.setAdapter(new FragmentAdapter(this, fragments));
        new TabLayoutMediator(mTabLayout, mViewPage, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(position == 0 ? "企业列表" : "协作通知");
            }
        }).attach();
    }

    @Override
    public void onClick(View view) {
        startActivity(new Intent(mActivity,AddEnterpriseActivity.class));
    }
}